package game.module.user.processor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import game.lan.bean.LoginSessionBean;
import game.lan.cache.LoginSessionCache;
import game.module.user.logic.PlayerManager;
import lion.common.MsgCodeAnn;
import lion.netty4.message.GamePlayer;
import lion.netty4.message.MyRequestMessage;
import lion.netty4.message.RequestMessageRaw;
import lion.netty4.message.RequestProtoMessage;
import lion.netty4.processor.MsgProcessor;
import lua.LuaMessageHall.C2SEnterHall;
import lua.LuaMessageHall.S2CEnterHall;

@MsgCodeAnn(msgcode = C2SEnterHall.id, accessLimit = 500)
public class EnterHallProcessor extends MsgProcessor {

	private static Logger logger = LoggerFactory.getLogger(EnterHallProcessor.class);

	private PlayerManager playerManager = PlayerManager.getInstance();

	@Override
	public void process(GamePlayer player, RequestMessageRaw request) throws Exception {
		C2SEnterHall reqMsg = C2SEnterHall.parse(request);
		long loginSessionId = reqMsg.sessionId;
		logger.info("enter hall,loginSessionId={}", loginSessionId);
		// 判断session是否有效
		LoginSessionBean loginSessionBean = LoginSessionCache.getInstance()
				.getLoginSessionBean(Long.valueOf(loginSessionId));
		if (loginSessionBean == null) {
			S2CEnterHall retMsg = new S2CEnterHall(0, 1, 0);
			player.writeAndFlush(retMsg.build(player.alloc()));
			return;
		}
		// 进入大厅
		playerManager.enterHall(player, loginSessionBean);
	}

	@Override
	public void process(GamePlayer player, RequestProtoMessage request) throws Exception {
		// null
	}

	@Override
	public void process(GamePlayer player, MyRequestMessage request) throws Exception {
		// null
	}

}
